package com.graduation.roombooking.controller.applet;

import com.graduation.roombooking.service.IRoomService;
import com.graduation.roombooking.service.UserService;
import com.graduation.roombooking.vo.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @Author:CaiShuangLian
 * @FileName:
 * @Date:Created in  2022/5/5 19:31
 * @Version:
 * @Description:TODO
 */
@RestController
@RequestMapping("/applet/room")
@Api(tags = "Applet——会议室模块")
public class AppletRoomController {
    @Autowired
    private IRoomService roomService;
    @Autowired
    private UserService userService;

    @ApiOperation("会议室列表(当companyName为null或者空字符串时，返回regionCode下所有会议室)")
    @ResponseBody
    @PostMapping("/list")
    public RespBean getRoomList(@RequestBody AppletRoomVo appletRoomVo, HttpServletRequest request, HttpServletResponse response){
        String ticket=appletRoomVo.getTicket();
        if(ticket!=null && !ticket.isEmpty()){
            //根据cookie获取用户信息
            UserVo userVo=userService.getUserByCookie(ticket,request,response);
            if(userVo!=null ){
//                //获取用户手机号
//                Long phone=userVo.getUserPhone();
//                return orderService.appoint(appointRoomVo,phone);
                return roomService.getAppletRoomList(appletRoomVo);

            }
        }
        return RespBean.error(RespBeanEnum.ILLEGAL_OPERATION);
    }

    @ApiOperation("会议室详情")
    @ResponseBody
    @PostMapping("/info")
    public RespBean getRoomInfo(@RequestBody RoomInfoVo roomInfoVo,HttpServletRequest request, HttpServletResponse response){
        String ticket=roomInfoVo.getTicket();
        if(ticket!=null && !ticket.isEmpty()){
            //根据cookie获取用户信息
            UserVo userVo=userService.getUserByCookie(ticket,request,response);
            if(userVo!=null ){
//                //获取用户手机号
//                Long phone=userVo.getUserPhone();
//                return orderService.appoint(appointRoomVo,phone);
                return roomService.getRoomInfo(roomInfoVo);

            }
        }
        return RespBean.error(RespBeanEnum.ILLEGAL_OPERATION);
    }
}
